package com.lottery.material.util;

import java.util.Random;
import java.util.UUID;

/**
 * @description 随机数生成工具类
 * @author sunny
 * @date 2018年7月19日 下午4:23:47
 */
@SuppressWarnings("ALL")
public class RandomUtil {

	/**
	 * @description 生产UUID
	 * @return 返回原始未做任何处理的36位的UUID字符串
	 */
	public static String getUuid() {
		String uuid = UUID.randomUUID().toString();
		return uuid;
	}

	/**
	 * @description 生产不带横线的UUID
	 * @return 返回已经去除了4个横线的32位的UUID字符串
	 */
	public static String getUuidNoLine() {
		String uuid = UUID.randomUUID().toString().replace("-", "");
		return uuid;
	}

	/**
	 * @description 根据指定长度生成数字加小写和大字字母随机字符
	 * @param length
	 * @return
	 */
	public static String getRandomNumChar(int length) {
		String base = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	/**
	 * @description 根据指定长度生成小写字母随机字符
	 * @param length
	 * @return
	 */
	public static String getRandomChar(int length) {
		String base = "abcdefghijklmnopqrstuvwxyz";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	/**
	 * @description 根据指定长度生成随机数字
	 * @param length
	 * @return
	 */
	public static String getRandomNum(int length) {
		String base = "0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		System.out.println(getRandomChar(2));
	}
}
